// -*- c-basic-offset: 2 default-tab-width: 2 indent-tabs-mode: t -*-
// vim: autoindent tabstop=2 noexpandtab shiftwidth=2 softtabstop=2
#ifndef __BUILTINS_H
#define __BUILTINS_H
#include "Any.h"
#include "Evaluator.h"

namespace R {
	class BuiltInMap {
			friend class Debugger;
			static int maplen;

		public:
			const char const * name;
			const int nbParams;
			const union {
				Any* (* builtin)(uint32_t nbArgs, Any **args);
				Any* (* special)(EnvInfo *envInfo, uint32_t nbArgs, Any **args);
			};
			const r_bool isSpecial;

			BuiltInMap(const char *nm, int prms, Any* (* funPtr)(uint32_t, Any **args)):
				name(nm), nbParams(prms), builtin(funPtr), isSpecial(0) {}

			BuiltInMap(const char *nm, int prms, Any* (* funPtr)(EnvInfo* env, uint32_t, Any **args)):
				name(nm), nbParams(prms), special(funPtr), isSpecial(1) {}

			Any* callBuiltIn(uint32_t nbArgs, Any **args); // For builtins
			Any* callSpecial(uint32_t nbArgs, Any **args); // For specials
			const char* getName() { return name; }

			static int getEntryID(const char *);
			static BuiltInMap *getEntry(int id);
			static BuiltInMap *getEntry(char *name);

			static int isValidEntry(int id){ return id > 0 && id < maplen; }
	};
}
#endif
